package com.hdax.dm.user.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.auth.code.CodeEnum;
import com.hdax.dm.auth.exception.DmException;
import com.hdax.dm.entity.user.User;
import com.hdax.dm.user.mappers.UserMapper;
import lombok.SneakyThrows;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @SneakyThrows
    @Override
    public User user(String phone) {
        if(ObjectUtils.isEmpty(phone)){
            throw new DmException(CodeEnum.USER_PHONE_NOT_EXISTS);
        }
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone",phone);
        User user = getOne(queryWrapper);
        if(user == null)
            throw new DmException(CodeEnum.USER_PHONE_NOT_EXISTS);
        return user;
    }
}
